<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en">
	<h:head />
	<body>
		<ui:composition template="/rootWeb.xhtml">
	    <ui:define name="header">
	        <title>数据字典类型列表</title>
	        <script type="text/javascript">
	        	//页面载入时注册
	        	jQuery(document).ready(function(){
	        		//鼠标移入
					jQuery("#typeTable_data tr").live("mouseover", function() {
					  	jQuery(this).css("background-color","#CCCCCC");
					});
					//鼠标移出
					jQuery("#typeTable_data tr").live("mouseout", function() {
					  	jQuery(this).css("background-color","white");
					});
				});
				function handleSaveDictionaryType(xhr, status, args) {
					if(args.error){
						alert(args.error);
					}else{
						addDictionaryTypeDlg.hide();
						alert(args.msg);
					}
				}
				function handleUpdateDictionaryType(xhr, status, args) {
					if(args.error){
						alert(args.error);
					}else{
						updateDictionaryTypeDlg.hide();
						alert("更新成功！");
					}
				}
				function resetQueryCondition(){
					jQuery("#queryCode").val('');
					jQuery("#queryName").val('');
				}
			</script>
	    </ui:define>
	    <ui:define name="body">
	    	<h:form id="form" prependId="false">
		    	<h:panelGrid id="queryGrid" columns="7">
		    		<h:outputLabel for="queryCode" value="类型代码："/>
		    		<p:inputText id="queryCode" value="#{dictionaryAction.queryType.typeCode}"/>
		    		<h:outputLabel for="queryName" value="类型名称："/>
		    		<p:inputText id="queryName" value="#{dictionaryAction.queryType.typeName}"/>
		    		<p:commandButton value="查询" action="#{dictionaryAction.queryResultBycondition}" update="typeTable"  icon="ui-icon-search"/>
		    		<p:commandButton value="重置" onclick="resetQueryCondition();"/>
		    		<p:commandButton value="加载所有记录" action="#{dictionaryAction.findAllDictionaryType}"  update="typeTable" rendered="false"/>
		    		<p:commandButton value="新增" action="#{dictionaryAction.addDictionaryType}"  update="addDictionaryTypeDlgID" oncomplete="addDictionaryTypeDlg.show();"/>
		    	</h:panelGrid> <p/>
		    	<p:dataTable id="typeTable" value="#{dictionaryAction.typeList}" var="dicType" rowKey="dicType" emptyMessage="没有记录！"
		    			paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
                 		paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
	    			<p:column headerText="类型名称">#{dicType.typeName}</p:column>
	    			<p:column headerText="类型代码">#{dicType.typeCode}</p:column>
	    			<p:column headerText="类型描述">#{dicType.typeDesc}</p:column>
	    			<p:column headerText="是否可用">
			            <h:outputText value="可用" rendered="#{dicType.available eq '0'}"/>
			            <h:outputText value="不可用" rendered="#{dicType.available eq '1'}"/>
	    			</p:column>
	    			<p:column headerText="操作">
	    				<p:commandLink value="修改" oncomplete="updateDictionaryTypeDlg.show();"  action="#{dictionaryAction.setUpdateType(dicType)}"
	    						 style="color:red" update=":updateForm:updateDictionaryTypeDlgID" rendered="#{dicType.typeCode ne 'MoldState' }">
	    				</p:commandLink>
					</p:column>
					
	    		</p:dataTable>
	    		
				<p:dialog id="addDictionaryTypeDlgID" header="增加字典类型" widgetVar="addDictionaryTypeDlg" modal="true" 
					resizable="false">

					<h:panelGrid columns="2" cellpadding="5">
						<h:outputLabel for="typeName" value="名称:" />
						<p:inputText value="#{dictionaryAction.selectedType.typeName}" id="typeName"  maxlength="100"/>

						<h:outputLabel for="typeCode" value="代码:" />
						<p:inputText value="#{dictionaryAction.selectedType.typeCode}" id="typeCode" maxlength="50"/>
						
			            <h:outputLabel for="typeDesc" value="描述:" />
						<p:inputTextarea value="#{dictionaryAction.selectedType.typeDesc}" id="typeDesc"  maxlength="250"/>

						<h:outputLabel for="typeAvailable" value="是否可用:" />
						 <h:selectOneMenu id="typeAvailable" value="#{dictionaryAction.selectedType.available}" >  
			                <f:selectItems value="#{dictionaryAction.availableItems}"/>
			            </h:selectOneMenu>  
			            
						<f:facet name="footer">
							<p:commandButton id="saveTypeBtn" value="保存" update="typeTable"
								actionListener="#{dictionaryAction.saveDictionaryType}"
								oncomplete="handleSaveDictionaryType(xhr, status, args)" />
						</f:facet>
					</h:panelGrid>

				</p:dialog>

			</h:form>
			
			<h:form prependId="false" id="updateForm">
			
	    		<p:dialog id="updateDictionaryTypeDlgID" header="更新字典类型" widgetVar="updateDictionaryTypeDlg" modal="true" 
					resizable="false">

					<h:panelGrid columns="2" cellpadding="5">
						<h:outputLabel for="typeName_update" value="名称:" />
						<p:inputText value="#{dictionaryAction.updateType.typeName}" id="typeName_update"  maxlength="100"/>

						<h:outputLabel for="typeCode_update" value="代码:" />
						<p:inputText value="#{dictionaryAction.updateType.typeCode}" id="typeCode_update" maxlength="50"/>
						
			            <h:outputLabel for="typeDesc_update" value="描述:" />
						<p:inputTextarea value="#{dictionaryAction.updateType.typeDesc}" id="typeDesc_update"  maxlength="250"/>

						<h:outputLabel for="typeAvailable_update" value="是否可用:" />
						 <h:selectOneMenu id="typeAvailable_update" value="#{dictionaryAction.updateType.available}" >  
			                <f:selectItems value="#{dictionaryAction.availableItems}"/>
			            </h:selectOneMenu>  
			            
						<f:facet name="footer">
							<p:commandButton id="updateTypeBtn" value="更新" update=":form:typeTable"
								actionListener="#{dictionaryAction.updateDictionaryType}"
								oncomplete="handleUpdateDictionaryType(xhr, status, args)" />
						</f:facet>
					</h:panelGrid>

				</p:dialog>
			
			</h:form>
	    </ui:define>
	</ui:composition>
	</body>
</html>
